import logging
import fileModel
from gensim.models import word2vec


def prepare_word_simility(path):
    model_name = "G:/我的本地文件/数据/w2v_pretrain/wiki.en.text.vector"
    model = word2vec.Word2Vec.load_word2vec_format(model_name)
    wordmap,id2word = fileModel.read_wordMap_and_id2word(path)

    with open(path+'.simility','w',encoding='utf-8') as f,open(path+'.wordmap','w',encoding='utf-8') as fw:
        for index in range(len(id2word)):
            print(id2word[index]+","+str(index))
            line = []
            if id2word[index] in model:
                simi_word = model.most_similar(id2word[index], topn=10000)
                for one in simi_word:
                    if one[1] > 0.7 and one[0] in wordmap:
                        line.append(str(wordmap[one[0]]))
            fw.write(id2word[index]+","+str(index)+"\n")
            f.write(' '.join(line)+"\n")


prepare_word_simility("G:\intellij\TopicModelForShortText\\data\\dblp-6\\dblp-6.data")
